package com.framework.util.datasource;


import java.sql.SQLException;
import java.util.Properties;

import org.springframework.jdbc.datasource.DriverManagerDataSource;

import com.framework.entity.DatacenterFormMap;


public class JDBCSource extends DriverManagerDataSource{
	
	
	public void changeJDBC(String url,String username,String password) {
		setUrl(url);
		setUsername(username);
		setPassword(password);
	}
	
	public void changeJDBC(Properties properties) throws Exception {
		setConnectionProperties(properties);
		setUrl(properties.getProperty("jdbc.url"));
		setUsername(properties.getProperty("jdbc.username"));
		setPassword(properties.getProperty("jdbc.password"));
	}
	
	public void changeJDBC(DatacenterFormMap datacenterFormMap) throws Exception {
		String db_username=datacenterFormMap.get("db_username").toString();
		String db_password=datacenterFormMap.get("db_password").toString();
		String db_position=datacenterFormMap.get("db_position").toString();
		String db_name=datacenterFormMap.get("db_name").toString();
		String url="jdbc:mysql://"+db_position+"/"+db_name;
		changeJDBC(url, db_username, db_password);
	}
}